package com.ioidea.ble.proto

import com.ioidea.base.util.ReportDataLogger
import com.ioidea.base.util.StringUtils

/**
 *
A172508548F2  sn    12个字节
150207        版本   6个字节
0000          亮度1  4个字节
0000          亮度2  4个字节
0000          亮度3  4个字节
00            状态   2个字节
000000000000000000000000000000000000000000000000000000000000000000000000  电表数据

除了亮度其他都是高位在前
 */
data class JKReportData(
    var sn: String,
    var version: String,
    var light1: Int,
    var light2: Int,
    var light3: Int,
    var controlType: Int,
    var electricTableData: String = ""
)


class ReportDataProtoBase(
    override var requestCommand: String = "STA",
    override var responseCommand: String = "STA"
) : ProtoBase() {


    fun parseJKReportDataResponse(sn: String, wholeData: String): JKReportData{
        this.sn = sn
        val radix = 16
        val data = removeHeadTail(wholeData)
        val lightSn = data.substring(0, 12)
        val version = StringUtils.covertVersionString(data.substring(12, 18))
        val light1 = StringUtils.reverseHexString(data.substring(18, 22)).toInt(radix)/10
        val light2 = StringUtils.reverseHexString(data.substring(22, 26)).toInt(radix)/10
        val light3 = StringUtils.reverseHexString(data.substring(26, 30)).toInt(radix)/10
        val status = data.substring(30, 32).toInt()
        val electricTableData = data.substring(32, data.length)
        val jkReportData =
            JKReportData(lightSn, version, light1, light2, light3, status, electricTableData)
        ReportDataLogger.hLog().e(jkReportData)
       return jkReportData
    }


}


